﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void LoginButton_Click(object sender, EventArgs e)
    {
        db database = new db();
        if (this.Search.Text.Trim() != "" )
        {
            this.Response.Redirect("Search.aspx?terms=" + this.Search.Text.Trim());
        }
        else
        {
            int userID = database.validUser(this.UserName.Text, this.Password.Text);
            if (userID != -1)
            {

                //code to store userdata in a authintiation ticket if we want to.
                // string userData = "datahere";
                //  FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, this.UserName.Text, DateTime.Now, DateTime.Now.AddMinutes(1440), this.RememberMe.Checked, userData);
                FormsAuthentication.SetAuthCookie(userID.ToString(), true);
                this.Response.Redirect("~/members/members.aspx");
            }
            this.lblBadLogin.Enabled = true;
            this.lblBadLogin.Visible = true;
        }
    }
}
